home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77710_inc_wsa.js < prev    next >
Encoding:
Text File  |  2003-02-21  |  17.3 KB  |  698 lines

  1. <meta http-equiv="Content-Type" content="text/html; charset=<%=GetCharSet()%>">
  2. <script language=javascript>
  3.  
  4.     //------------------------------------------------------------------------
  5.     // 
  6.     //    inc_wsa.js:            Resuable  JavaScript functions 
  7.     //                        used accross all the pages
  8.     //
  9.     // Copyright (c) Microsoft Corporation.  All rights reserved.
  10.     //
  11.     //    Date             Description
  12.     //  18/09/2000        Created date
  13.     //------------------------------------------------------------------------
  14.         
  15.         // Local variables
  16.          var flag="false";             
  17.          
  18.     //------------------------------------------------------------------------
  19.     // Function to clear the error messages (if any on screen) whenever required
  20.     //------------------------------------------------------------------------
  21.     
  22.     function ClearErr()
  23.     { 
  24.         // checking for the browser type 
  25.         if (IsIE()) 
  26.         {
  27.             document.all("divErrMsg").innerHTML = "";
  28.             // removing the event handling
  29.             document.frmTask.onkeypress = null ;
  30.         }
  31.     }    
  32.     
  33.     //------------------------------------------------------------------------
  34.        // Function:    To check if given input is INTEGER or not
  35.     // input:        Text value, text length
  36.     // returns:        True if the field is integer else false
  37.     //------------------------------------------------------------------------
  38.     
  39.     function isInteger(strText)
  40.     {
  41.          var blnResult = true;
  42.          var strChar;
  43.          // checking for null string 
  44.          if (strText.length==0)  
  45.          {
  46.             blnResult=false;
  47.          }
  48.          
  49.          for(var i=0;i < strText.length;i++)
  50.          {
  51.             strChar=strText.substring(i,i+1);
  52.             if(strChar < "0" || strChar > "9")
  53.             { 
  54.               blnResult = false;
  55.             }
  56.          } 
  57.          return blnResult;
  58.     }
  59.         
  60.     
  61.     //------------------------------------------------------------------------
  62.     // Function:    To count the number of occurences of given character in the text
  63.     // input:        strText-sourceString
  64.     //        :        charToCount-character to be checked 
  65.     // returns:        The count of no of character
  66.     //------------------------------------------------------------------------
  67.     
  68.     function countChars(strText,charToCount)
  69.     {
  70.         var intStartingPosition = 0;
  71.         var intFoundPosition =0;
  72.         var intCount = 0;
  73.         
  74.         // checking for the null character    
  75.         if (charToCount=="")
  76.         {
  77.             return intCount;
  78.         }    
  79.         while((intFoundPosition=strText.indexOf(charToCount,intStartingPosition)) >= 0)
  80.         {
  81.             intCount++;
  82.             intStartingPosition = intFoundPosition + 1;
  83.         }
  84.             
  85.         return intCount ;
  86.     }
  87.     
  88.     //------------------------------------------------------------------------
  89.     // Function:    Check to see if all characters in string are spaces
  90.     // input:    strText-sourceString
  91.     // returns:
  92.     //  0 - not all spaces
  93.     //  1 - all spaces
  94.     //------------------------------------------------------------------------
  95.     
  96.     function IsAllSpaces(strText)
  97.     {
  98.         var bIsAllSpaces;
  99.  
  100.         if (countChars(strText," ") == strText.length)
  101.         {
  102.             bIsAllSpaces = 1;
  103.         }    
  104.         else
  105.         {
  106.             bIsAllSpaces = 0;
  107.         }
  108.             
  109.         return bIsAllSpaces ;
  110.     }
  111.     
  112.     
  113.     //------------------------------------------------------------------------
  114.     // Function:        isValidIP
  115.     // Description:        to validate the IP address
  116.     // input:            IP address text object
  117.     // returns:0 if it is valid 
  118.     // 1    Empty
  119.     // 2    Invalid Format, number of dots is not 3
  120.     // 3    non-integers present in the value
  121.     // 4    start ip > 223
  122.     // 5    Should not start with 127
  123.     // 6    out of bound
  124.     // 7    All zeros
  125.     // 8    Should not be 0        
  126.     // support functions: 
  127.     //        IsAllSpaces
  128.     //        countChars
  129.     //        isInteger
  130.     //------------------------------------------------------------------------
  131.     
  132.     function isValidIP(objIP) 
  133.     {
  134.         var strIPtext = objIP.value; 
  135.         if ((strIPtext.length == 0) || IsAllSpaces(strIPtext)) 
  136.         { 
  137.             // IP Empty
  138.             return 1;
  139.         }
  140.         
  141.         if ( countChars(strIPtext,".") != 3) 
  142.         { 
  143.             // Invalid Format, number of dots is not 3
  144.             return 2;
  145.         }
  146.         var arrIP = strIPtext.split(".");
  147.             
  148.         for(var i = 0; i < 4; i++)
  149.         {
  150.             if ( (arrIP[i].length < 1 ) || (arrIP[i].length > 3 ) )
  151.             {
  152.                 // Invalid Format, continuous dots or more than 3 digits given between dots
  153.                 return 2;
  154.             }
  155.                 
  156.             if ( !isInteger(arrIP[i]) )
  157.             {
  158.                 // non-integers present in the value
  159.                 return 3;
  160.             }
  161.                 
  162.             arrIP[i] = parseInt(arrIP[i]);
  163.                 
  164.             if(i == 0)
  165.             {
  166.                 // start IP value
  167.                 if(arrIP[i] == 0)
  168.                 {
  169.                     // start IP value must not be 0
  170.                     return 8;
  171.                 }
  172.  
  173.                 if(arrIP[i] > 223)
  174.                 {
  175.                     // start IP must not be > 223
  176.                     return 4;
  177.                 }
  178.                 if(arrIP[i] == 127)
  179.                 {
  180.                     // start IP must not be 127 - Loopback ip
  181.                     return 5;
  182.                 }
  183.             }
  184.             else
  185.             {
  186.                 // the 2nd, 3rd and 4th IP values between the dots
  187.                 // these must not be more than 255
  188.                 if (arrIP[i] > 255)
  189.                 {
  190.                     // IP out of bound
  191.                     return 6;
  192.                 }
  193.             }
  194.         }
  195.             
  196.         objIP.value = arrIP.join(".");
  197.             
  198.         if(objIP.value == "0.0.0.0")
  199.         {
  200.             // IP all zeros
  201.             return 7;
  202.         }    
  203.             
  204.         return 0;
  205.             
  206.     }    // end of isValidIP
  207.     
  208.     //------------------------------------------------------------------------
  209.     // Function        :checkkeyforIPAddress
  210.     // Description    :function to allow only dots and numbers
  211.     // input        :Object    -TextBox Object
  212.     // returns        :none
  213.     //------------------------------------------------------------------------
  214.     
  215.     function checkKeyforIPAddress(obj)
  216.     {
  217.         // Clear any previous error messages
  218.         ClearErr();
  219.         if (!(window.event.keyCode >=48  && window.event.keyCode <=57 || window.event.keyCode == 46))
  220.         {
  221.             window.event.keyCode = 0;
  222.             obj.focus();
  223.         }
  224.     }
  225.     
  226.     //------------------------------------------------------------------------
  227.     // Function        :checkkeyforNumbers
  228.     // Description    :function to allow only numbers 
  229.     // input        :Object    -TextBox Object
  230.     // returns        :none
  231.     //------------------------------------------------------------------------
  232.     
  233.     function checkKeyforNumbers(obj)
  234.     {
  235.         // Clear any previous error messages        
  236.         ClearErr();        
  237.         
  238.         if(window.event.keyCode == 13 || window.event.keyCode == 27)
  239.             return;
  240.             
  241.         if (!(window.event.keyCode >=48  && window.event.keyCode <=57 ))
  242.         {        
  243.             window.event.keyCode = 0;
  244.             obj.focus();
  245.         }
  246.     }
  247.     
  248.     //------------------------------------------------------------------------
  249.     // Function        :checkKeyforNumbersDecimal
  250.     // Description    :function to allow only numbers 
  251.     // input        :Object    -TextBox Object
  252.     // returns        :none
  253.     //------------------------------------------------------------------------    
  254.     function checkKeyforNumbersDecimal(obj)
  255.     {
  256.         // Clear any previous error messages
  257.         
  258.             ClearErr();
  259.             
  260.             if(window.event.keyCode == 13 || window.event.keyCode == 27)
  261.             return;
  262.             
  263.             if (!((window.event.keyCode >=48  && window.event.keyCode <=57)))
  264.             {
  265.                     window.event.keyCode = 0;
  266.                     obj.focus();
  267.             }
  268.     }
  269.     
  270.     
  271.     //------------------------------------------------------------------------
  272.     // Function        :checkKeyforCharacters
  273.     // Description    :function to allow only numbers 
  274.     // input        :Object    -TextBox Object
  275.     // returns        :none
  276.     //------------------------------------------------------------------------
  277.     
  278.     function checkKeyforCharacters(obj)
  279.     {
  280.         // Clear any previous error messages
  281.         ClearErr();
  282.         if (!((window.event.keyCode >=65  && window.event.keyCode <=92)||
  283.             (window.event.keyCode >=97  && window.event.keyCode <=123)||
  284.             (window.event.keyCode >=48  && window.event.keyCode <=57)||
  285.             (window.event.keyCode == 45)||
  286.             (window.event.keyCode == 95)))
  287.         {
  288.             window.event.keyCode = 0;
  289.             obj.focus();
  290.         }
  291.     }
  292.     
  293.     //------------------------------------------------------------------------
  294.     // Function        :headerscheckKeyforCharacters
  295.     // Description    :function to allow only numbers 
  296.     // input        :Object    -TextBox Object
  297.     // returns        :none
  298.     //------------------------------------------------------------------------
  299.     function headerscheckKeyforCharacters(obj)
  300.     {
  301.         ClearErr();
  302.         if(window.event.keyCode == 59 || window.event.keyCode ==47 ||
  303.         window.event.keyCode == 63 || window.event.keyCode == 58 ||
  304.         window.event.keyCode==64 || window.event.keyCode == 38 ||
  305.         window.event.keyCode == 61 || window.event.keyCode == 36 || 
  306.         window.event.keyCode == 43 ||window.event.keyCode == 44)
  307.         {
  308.             window.event.keyCode = 0;
  309.             obj.focus();
  310.         }
  311.     }
  312.     //------------------------------------------------------------------------
  313.     // Function        :isvalidchar
  314.     // Description    :Function to check whether the input is valid or not
  315.     // input        :Invalid char list
  316.     //                 The input string    
  317.     // returns        :true if it doesnt contain the invalid chars; else false 
  318.     //------------------------------------------------------------------------    
  319.     // Checks For Invalid Key Entry
  320.     
  321.     function isvalidchar(strInvalidChars,strInput)
  322.     {
  323.          var reInvalid = eval(strInvalidChars);
  324.                
  325.               if(reInvalid.test(strInput))
  326.               {
  327.                   return false;
  328.               }        
  329.               else
  330.               {
  331.                   return true;
  332.               }
  333.     }
  334.  
  335.  
  336.     //------------------------------------------------------------------------
  337.     // Function        :checkkeyforNumbers
  338.     // Description    :Function to check only numbers
  339.     // ------------------------------------------------------------------------    
  340.  
  341.     function checkkeyforNumbers(obj)
  342.     {
  343.         ClearErr();
  344.         if(window.event.keyCode == 13 || window.event.keyCode == 27)
  345.             return;
  346.             
  347.         if (!(window.event.keyCode >=48  && window.event.keyCode <=57))
  348.         {
  349.             window.event.keyCode = 0;
  350.             obj.focus();
  351.         }
  352.     }
  353.  
  354.     //------------------------------------------------------------------------
  355.     // Function        :checkfordefPortValue
  356.     // Description    :Function to set the default port value
  357.     // -----------------------------------------------------------------------
  358.     function checkfordefPortValue(obj)
  359.     {
  360.         var portValue = obj.value;
  361.         
  362.         if (portValue == "")
  363.         obj.value = 80;
  364.     }
  365.         
  366.  
  367.     //------------------------------------------------------------------------
  368.     // Function        :checkUserLimit
  369.     // Description    :Function to check the limit entered
  370.     // ------------------------------------------------------------------------    
  371.  
  372.     function checkUserLimit(obj,str)
  373.             {
  374.                 var intNoofUsers=obj.value;
  375.                 
  376.                 if(str=="siteid")
  377.                 {
  378.                     if (intNoofUsers > 999)
  379.                         {
  380.                             obj.value="";
  381.                             obj.focus();
  382.                         }
  383.                 }
  384.                 
  385.                 // Check whether port value greater than 65535
  386.                 else if(str=="port")
  387.                 {                     
  388.                 
  389.                     if (intNoofUsers > 65535)
  390.                     {
  391.                         obj.value=80;
  392.                         obj.focus();
  393.                     }
  394.                  }
  395.                  
  396.                  // Check whether no of connections greater than 2000000000
  397.                  
  398.                  if(str=="con")
  399.                 {
  400.                     if (intNoofUsers > 2000000000)
  401.                         {
  402.                             obj.value="";
  403.                             obj.focus();
  404.                         }
  405.                 }
  406.                 
  407.                 // Check whether filesize greater than 4000 in Weblog and FTPlog settings
  408.                 if(str=="filesize")
  409.                 {
  410.                     if (intNoofUsers > 4000)
  411.                         {
  412.                             obj.value="";
  413.                             obj.focus();
  414.                         }
  415.                 }
  416.                 
  417.                 // Check for script timeout
  418.                 
  419.                 if(str=="scripttimeout")
  420.                 {    
  421.                     if (intNoofUsers > 2147483647)
  422.                         {
  423.                             obj.value="1";
  424.                             obj.focus();
  425.                         }
  426.                 }
  427.                 
  428.                 // Check for maximum ftp connections
  429.                 
  430.                 if(str=="conftp")
  431.                 {
  432.                     if (intNoofUsers > 4294967295)
  433.                         {
  434.                             obj.value="";
  435.                             obj.focus();
  436.                         }
  437.                 }
  438.                 
  439.                 // Check for connection timeout
  440.                 if(str=="contimeout")
  441.                 {
  442.                     if (intNoofUsers > 2000000)
  443.                         {
  444.                             obj.value="";
  445.                             obj.focus();
  446.                         }
  447.                 }
  448.                          
  449.           }  // End of the function
  450.     
  451.     //------------------------------------------------------------------------------------
  452.     // Function        :GenerateAdmin
  453.     // Description    :Function to generate directory path concatenated with site identifier
  454.     // -----------------------------------------------------------------------------------
  455.     
  456.     function GenerateAdmin()
  457.     {
  458.                 
  459.         var strID = document.frmTask.txtSiteID.value;                            
  460.         
  461.         strID = LTrimtext(strID); // Removes all leading spaces.         
  462.         
  463.         strID = RTrimtext(strID); // Removes all trailing spaces.    
  464.         
  465.         document.frmTask.txtSiteID.value = strID;    
  466.         
  467.         
  468.         if(strID.length > 0)
  469.         {
  470.             document.frmTask.txtSiteAdmin.value = strID + "_Admin";
  471.             document.frmTask.txtDir.value = document.frmTask.hdnWebRootDir.value + "\\" + strID;
  472.         }
  473.         else
  474.         {
  475.             document.frmTask.txtSiteAdmin.value = "";
  476.             document.frmTask.txtDir.value = "";
  477.         }
  478.     }
  479.     
  480.     
  481.     //------------------------------------------------------------------------
  482.     // Function        :checkKeyforSpecialCharacters
  483.     // Description    :function to allow Characters 
  484.     // input        :Object    -TextBox Object
  485.     // returns        :none
  486.     //------------------------------------------------------------------------
  487.     
  488.     function checkKeyforSpecialCharacters(obj)
  489.     {
  490.         // Clear any previous error messages
  491.         ClearErr();
  492.         if (window.event.keyCode == 47 || window.event.keyCode == 42 || window.event.keyCode == 63 || window.event.keyCode == 34 || window.event.keyCode == 60 || window.event.keyCode == 62 || window.event.keyCode == 124)
  493.         {
  494.             window.event.keyCode = 0;
  495.             obj.focus();
  496.         }
  497.     }
  498.     
  499.     //------------------------------------------------------------------------
  500.     // Function        :IsAllDots
  501.     // Description    :function to check for dots
  502.     // input        :String
  503.     // returns        :Boolean
  504.     //------------------------------------------------------------------------
  505.         
  506.     function IsAllDots(strText)
  507.     {
  508.         var bIsAllSpaces;
  509.  
  510.         if (countChars(strText,".") == strText.length)
  511.         {
  512.             bIsAllSpaces = 1;
  513.         }    
  514.         else
  515.         {
  516.             bIsAllSpaces = 0;
  517.         }
  518.             
  519.         return bIsAllSpaces ;
  520.     }    
  521.     
  522.     
  523.     //------------------------------------------------------------------------
  524.     // Function        :LTrimtext
  525.     // Description    :function to remove left trailing spaces 
  526.     // input        :String
  527.     // returns        :String
  528.     //------------------------------------------------------------------------
  529.     function LTrimtext(str)
  530.     {
  531.         var res="", i, ch, index;
  532.         x = str.length;
  533.         index = "false";
  534.         
  535.         for (i=0; i < str.length; i++)
  536.         {
  537.             ch = str.charAt(i);
  538.             if (index == "false")
  539.             {
  540.                 if (ch != ' ')
  541.                 {
  542.                     index = "true";
  543.                     res = ch;
  544.                 }
  545.             }
  546.             else
  547.             {
  548.                 res = res + ch;
  549.             }     
  550.         }
  551.         return res;
  552.     }
  553.     
  554.     
  555.     //------------------------------------------------------------------------
  556.     // Function        :RTrimtext
  557.     // Description    :function to remove right trailing spaces 
  558.     // input        :String
  559.     // returns        :String
  560.     //------------------------------------------------------------------------
  561.     function RTrimtext(str)
  562.     {
  563.         var res="", i, ch, index, j, k;
  564.         x = str.length;
  565.         index = "false";
  566.                 
  567.         if(x==0 || x==1) 
  568.             return str;
  569.         
  570.         for(i=x; i >= 0; i--)
  571.         {
  572.             ch = str.charAt(i);                        
  573.             
  574.             if (index == "false")
  575.             {
  576.                 
  577.                 if( (ch == ' ') || (ch == '') )
  578.                 {
  579.                     continue;
  580.                 }
  581.                 else
  582.                 {                
  583.                     index = "true";                    
  584.                     j = i;        
  585.                 }
  586.             }     
  587.                   
  588.             if (index == "true")
  589.             {
  590.                 for(k=0; k<=j; k++)
  591.                 {
  592.                     res = res + str.charAt(k);
  593.                 }                
  594.                 return res;
  595.             }    
  596.             
  597.         }    
  598.     }
  599.     
  600.     
  601.     //------------------------------------------------------------------------
  602.     // Function        :charCount
  603.     // Description    :Function returns length of string
  604.     // input        :String
  605.     // returns        :Integer
  606.     //------------------------------------------------------------------------
  607.     
  608.     function charCount(strID)
  609.     {
  610.         var Len = strID.length;
  611.         Len--;        
  612.         while (Len > 0)
  613.         {
  614.             var x = strID.charCodeAt(Len);
  615.             if(x!= 32)
  616.             {
  617.              return Len;
  618.             }            
  619.             Len--;            
  620.         }    
  621.     }
  622.     
  623.     //Check whether enterKey is pressed        
  624.     function GenerateDir()
  625.     {
  626.         var strID = document.frmTask.txtSiteID.value;            
  627.         var Keyc = window.event.keyCode; 
  628.         if (Keyc == 13)
  629.         {            
  630.             if(document.frmTask.txtSiteID.value=="")
  631.             {
  632.                 DisplayErr("<%=Server.HTMLEncode(L_ID_NOTEMPTY_ERROR_MESSAGE)%>");
  633.                 document.frmTask.txtSiteID.focus();
  634.                 return false;
  635.             }
  636.             else
  637.             {            
  638.                 GenerateAdmin();
  639.                 return true;
  640.             }                    
  641.         }
  642.     }
  643.     function checkKeyforValidCharacters(strID,identifier)
  644.     {    
  645.         var i;
  646.         var colonvalue;
  647.         var charAtPos;
  648.         var len = strID.length;
  649.         if(len > 0)
  650.         {        
  651.             colonvalue = 0;
  652.             
  653.             for(i=0; i < len;i++)
  654.             {
  655.                    charAtPos = strID.charCodeAt(i);    
  656.                     
  657.                 if (identifier == "id")
  658.                 {
  659.                     if(charAtPos ==47 || charAtPos == 92 || charAtPos ==58 || charAtPos == 42 || charAtPos == 63 || charAtPos == 34 || charAtPos == 60 || charAtPos == 62 || charAtPos == 124 || charAtPos == 91 || charAtPos == 93 || charAtPos == 59 || charAtPos == 43 || charAtPos == 61 || charAtPos == 44)
  660.                     {                        
  661.                             
  662.                         DisplayErr("<%= Server.HTMLEncode(L_SITE_IDENTIFIER_EMPTY_TEXT) %>");
  663.                         //document.frmTask.txtSiteID.value = "";
  664.                         document.frmTask.txtSiteID.focus();
  665.                         return false;
  666.                     }
  667.                 }
  668.             
  669.                 if(identifier == "dir")
  670.                 {                        
  671.                     if(charAtPos ==58)
  672.                     {                            
  673.                         colonvalue = colonvalue + 1;                            
  674.                         if (colonvalue > 1)
  675.                         {
  676.                             DisplayErr("<%= Server.HTMLEncode(L_INVALID_DIR_ERRORMESSAGE) %>");
  677.                             document.frmTask.txtDir.value = strID;
  678.                             document.frmTask.txtDir.focus();
  679.                             return false;
  680.                          }                        
  681.                      }    
  682.                     
  683.                     if(charAtPos ==47 || charAtPos == 42 || charAtPos == 63 || charAtPos == 34 || charAtPos == 60 || charAtPos == 62 || charAtPos == 124 || charAtPos == 91 || charAtPos == 93 || charAtPos == 59 || charAtPos == 43 || charAtPos == 61 || charAtPos == 44)
  684.                     {    
  685.                         DisplayErr("<%= Server.HTMLEncode(L_INVALID_DIR_ERRORMESSAGE)%>");
  686.                         document.frmTask.txtDir.value = strID;
  687.                         document.frmTask.txtDir.focus();
  688.                         return false;
  689.                     }
  690.                 }        
  691.                     
  692.             }
  693.                 
  694.             return true;
  695.         }         
  696.     }    
  697.     
  698. </script>